import Http from "../utils/http";
import Base from "./base";

class Service extends Base{
    async getServiceList(category_id = null,type = null) {

        if(!this.hasMoreData){
            return this.data
        }

        const serviceList = await Http.request({
            url : "/v1/service/list",
            data : {
                page : this.page,
                count : this.count,
                category_id : category_id || "",
                type :type || ""
            }
        })


        this.data = this.data.concat(serviceList.data)

        this.hasMoreData = !(this.page === serviceList.last_page)

        this.page++

        return this.data
    }

    static getServiceById(serviceId){
        return Http.request({
            url : `/v1/service/${serviceId}`
        })
    }



    static updateServiceStatus(serviceId,action){
        return Http.request({
            url : `/v1/service/${serviceId}`,
            method : "POST",
            data : {
                action
            }
        })
    }

    // 创建服务
    static publishService(serviceData){
        return Http.request({
            url: '/v1/service',
            method: 'POST',
            data: serviceData
        })
    }


    //编辑服务
    static editService(serviceId, serviceData){
        return Http.request({
            url: `/v1/service/${serviceId}`,
            method: 'PUT',
            data: serviceData
        })
    }
}

export default  Service